﻿module Sustainalytics.Shell.Admin {

    import Common = Sustainalytics.Common;
    import Navigation = Sustainalytics.Navigation;
    import Routing = Sustainalytics.Routing;



    var mod = angular.module(shellAdminModuleName);


    // configure module
    mod.config([Sustainalytics.Routing.routingServiceName + 'Provider', '$httpProvider', (routingProvider: Routing.IRoutingStateServiceProvider, $httpProvider, $urlRouterProvider) => {

        $httpProvider.interceptors.push(Sustainalytics.Authentication.authenticationHttpInterceptorName);

        //$urlRouterProvider.when('/research/:companyName', '/research/overview/:companyName');

        routingProvider

            .state('accounts',
            {
                url: '/accounts', templateUrl: 'views/Accounts/Accounts.html', controller: 'AccountsController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/Accounts.Admin/module.json'])

            .state('accountDetails',
            {
                url: '/account/:accountId', templateUrl: 'views/Accounts/AccountDetails.html', controller: 'AccountDetailsController'
            },
            new Routing.RouteSecurity().addAdminResource(),

            ['modules/Accounts.Admin/module.json'])
            .state('ipaccount',
            {
                url: '/ipaccount', templateUrl: 'views/Accounts/AccountIpAuthentication.html', controller: 'IpAuthenticationController'
            },
            new Routing.RouteSecurity().addAdminResource(),

            ['modules/Accounts.Admin/module.json'])
            .state('ipaccountDetails',
                {
                    url: '/ipaccount/:accountId', templateUrl: 'views/Accounts/AccountIpAuthenticationDetail.html', controller: 'IpAuthenticationDetailsController'
                },
                new Routing.RouteSecurity().addAdminResource(),

            ['modules/Accounts.Admin/module.json'])

            .state('users',
            {
                url: '/users', templateUrl: 'views/Users/Users.html', controller: 'UsersController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/Accounts.Admin/module.json'])

            .state('userDetails',
            {
                url: '/user/:userId', templateUrl: 'views/Users/UserDetails.html', controller: 'UserDetailsController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/Accounts.Admin/module.json'])

            .state('NewsAdd',
            {
                url: '/news/add', templateUrl: 'views/News/NewsAdd.html', controller: 'NewsAddController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/News.Admin/module.json'])

            .state('NewsEdit',
            {
                url: '/news/edit/:id', templateUrl: 'views/News/NewsEdit.html', controller: 'NewsEditController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/News.Admin/module.json'])

            .state('newsList',
            {
                url: '/news', templateUrl: 'views/News/NewsList.html', controller: 'NewsListController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/News.Admin/module.json'])

            .state('notifications',
            {
                url: '/notifications', templateUrl: 'views/Notifications/NotificationAddEdit.html', controller: 'NotificationAddEditController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/Notifications.Admin/module.json'])

            .state('events',
            {
                url: '/events', templateUrl: 'views/Events/EventsList.html', controller: 'EventsListController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/Events.Admin/module.json'])

            .state('eventAdd',
            {
                url: '/events/add', templateUrl: 'views/Events/EventAddEdit.html', controller: 'EventAddEditController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/Events.Admin/module.json'])

            .state('eventEdit',
            {
                url: '/events/edit/:id', templateUrl: 'views/Events/EventAddEdit.html', controller: 'EventAddEditController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/Events.Admin/module.json'])

            .state('insightsList',
            {
                url: '/insights', templateUrl: 'views/Insights/InsightList.html', controller: 'InsightsListController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/Insights.Admin/module.json'])

            .state('insightAdd',
            {
                url: '/insights/add', templateUrl: 'views/Insights/InsightAddEdit.html', controller: 'InsightsAddEditController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/Insights.Admin/module.json'])

            .state('insightEdit',
            {
                url: '/insights/edit/:id', templateUrl: 'views/Insights/InsightAddEdit.html', controller: 'InsightsAddEditController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/Insights.Admin/module.json'])

            .state('esgratings',
            {
                url: '/esgratings', templateUrl: 'views/Tools/EsgRatings.html', controller: 'ToolsController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/ESGRatings.Admin/module.json', 'modules/Tools.Admin/module.json'])

            .state('universes',
            {
                url: '/universes', templateUrl: 'views/Tools/universes.html', controller: 'UniversesController'
            },

            new Routing.RouteSecurity().addAdminResource(),
            ['modules/Universes.Admin/module.json', 'modules/Tools.Admin/module.json'])

            .state('claims',
            {
                url: '/claims', templateUrl: 'views/Tools/claims.html', controller: 'ToolsController'
            },


            new Routing.RouteSecurity().addAdminResource(),
            ['modules/ESGRatings.Admin/module.json', 'modules/Tools.Admin/module.json'])

            .state('esgFocusThresholds',
            {
                url: '/esgFocusThresholds', templateUrl: 'views/Tools/EsgfocusThresholds.html', controller: 'ToolsController'
            },

            new Routing.RouteSecurity().addAdminResource(),
            ['modules/ESGRatings.Admin/module.json', 'modules/Tools.Admin/module.json'])

            .state('esgFocusThresholdsPercentile',
            {
                url: '/esgFocusThresholdsPercentile', templateUrl: 'views/Tools/EsgfocusThresholdsPercentile.html', controller: 'ToolsController'
            },

            new Routing.RouteSecurity().addAdminResource(),
            ['modules/Tools.Admin/module.json'])

            .state('productinvolvement',
            {
                url: '/productinvolvement', templateUrl: 'views/ProductInvolvement/ProductInvolvement.html', controller: 'PIInputFileController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/PI.Admin/module.json'])

            .state('weightMatricesUpload',
            {
                url: '/weightMatricesUpload', templateUrl: 'views/ESGRatings/WeightMatricesUpload.html', controller: 'WeightMatricesController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/ESGRatings.Admin/module.json'])

            .state('FRWeightMatricesUpload',
            {
                url: '/FRWeightMatricesUpload', templateUrl: 'views/ESGRatings/FRWeightMatricesUpload.html', controller: 'WeightMatricesController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/ESGRatings.Admin/module.json'])

            .state('weightMatricesDownload',
            {
                url: '/weightMatricesDownload', templateUrl: 'views/ESGRatings/WeightMatricesDownload.html', controller: 'WeightMatricesController' 
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/ESGRatings.Admin/module.json'])

            .state('testesgratings',
            {
                url: '/testesgratings', templateUrl: 'views/ESGRatings/TestESGRatings.html', controller: 'TestESGRatingsController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/ESGRatings.Admin/module.json'])

            .state('esgProfile',
            {
                url: '/esgProfile', templateUrl: 'views/ESGRatings/EsgProfile.html', controller: 'ESGProfileController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/ESGRatings.Admin/module.json'])
           
            .state('ftpaccountinfo',
            {
                url: '/ftpaccountinfo', templateUrl: 'views/FTPReports/FTPReports.html', controller: 'ReportFTPController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/Tools.Admin/module.json'])

            .state('ftpclientreport',
            {
                url: '/ftpclientreport', templateUrl: 'views/FTPReports/FTPClientReports.html', controller: 'FtpClientReportController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/Tools.Admin/module.json'])

            .state('referenceUniverses',
            {
                url: '/referenceUniverses', templateUrl: 'views/ESGRatings/referenceUniverses.html', controller: 'ReferenceUniversesController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/ESGRatings.Admin/module.json'])
            .state('keyESGIssuesUpload',
            {
                url: '/keyESGIssuesUpload', templateUrl: 'views/ESGRatings/KeyESGIssuesUpload.html', controller: 'KeyESGIssuesController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/ESGRatings.Admin/module.json'])

            .state('forgotPassword',
            {
                url: '/forgotPassword', templateUrl: 'views/Login/ForgotPassword.html', controller: Sustainalytics.Security.Login.accountControllerName
            },
            new Routing.RouteSecurity().setLogout(true),
            [])

            .state('forgotPasswordConfirmation',
            {
                url: '/forgotPasswordConfirmation', templateUrl: 'views/Login/ForgotPasswordConfirmation.html', controller: Sustainalytics.Security.Login.accountControllerName
            },
            new Routing.RouteSecurity().setLogout(true),
            [])

            .state('userChangePassword',
            {
                url: '/changePassword/:user', templateUrl: 'views/Login/ChangePassword.html', controller: Sustainalytics.Security.Login.accountControllerName
            },
            new Routing.RouteSecurity().setLogout(true),
            [])

            .state('/changePasswordTempKey',
            {
                url: '/changePassword/:user/:tempKey', templateUrl: 'views/Login/ChangePassword.html', controller: Sustainalytics.Security.Login.accountControllerName
            },
            new Routing.RouteSecurity().setLogout(true),
            [])

            .state('passwordExpired',
            {
                url: '/passwordExpired', templateUrl: 'views/Login/PasswordExpired.html', controller: Sustainalytics.Security.Login.accountControllerName
            },
            new Routing.RouteSecurity().setLogout(true),
            [])

            .state('lrtmtest',
            {
                url: '/lrtmtest', templateUrl: '/views/LongRunningTaskManagerTest.html', controller: 'LongRunningTaskManagerTestController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/LRTMTest/module.json'])

            .state('login',
            {
                url: '/login', templateUrl: 'views/Login/Login.html', controller: Sustainalytics.Security.Login.accountControllerName
            },
            new Routing.RouteSecurity().setLogout(true),
            [])

            .state('governancereports',
            {
                url: '/governancereports', templateUrl: 'views/GovernanceReports/CompanySearch.html', controller: 'GovernanceCompanySearchController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/GovernanceReports.Admin/module.json', 'modules/CompanySearch.Admin/module.json'])

            //.state('researchOverviewCompany',
            //{
            //    url: '/research/overview/:companyName', templateUrl: '/views/Research/CompanyOverview/Company.html', controller: 'CompanyOverviewController'
            //},
            //null,
            //['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/CompanyOverview/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Research/module.json', 'modules/Company/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('governancereportEdit',
            {
                url: '/governancereports/:id', templateUrl: 'views/GovernanceReports/CompanyView.html', controller: 'CompanyViewController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/GovernanceReports.Admin/module.json', 'modules/CompanySearch.Admin/module.json'])

            //.state('toolsFilters',
            //{
            //    url: '/tools/:targetType', templateUrl: '/views/Tools/ScreeningTool/Filters.html', controller: 'FiltersController', controllerAs: 'fltCtrl'
            //},
            //new Routing.RouteSecurity().addAdminResource(),
            //['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Company/module.json', 'modules/ScreeningTool/module.json'])

            .state('toolsScreening',
            {
                url: '/tools/screening', templateUrl: 'views/Tools/ScreeningTool/Filters.html', controller: 'FiltersController', controllerAs: 'fltCtrl'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Company/module.json', 'modules/ScreeningTool/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('toolsReport',
            {
                url: '/tools/report', templateUrl: 'views/Tools/ScreeningTool/Filters.html', controller: 'FiltersController', controllerAs: 'fltCtrl'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Company/module.json', 'modules/ScreeningTool/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            //.state('filterDetails',
            //{
            //    url: '/filters/:filterId', templateUrl: '/views/Tools/ScreeningTool/FilterEdit.html', controller: 'EditFilterController'
            //},
            //new Routing.RouteSecurity().addAdminResource(),
            //['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Company/module.json', 'modules/ScreeningTool/module.json'])

            .state('editFilterDetails',
            {
                url: '/tools/screening/filters/:filterId', templateUrl: 'views/Tools/ScreeningTool/FilterEdit.html', controller: 'EditFilterController'
            },
            new Routing.RouteSecurity().addResource({ verb: 'GET', resource: 'api/v1/filters/{filterId}', parameters: [] }),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Company/module.json', 'modules/ScreeningTool/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('editReportDetails',
            {
                url: '/tools/report/filters/:filterId', templateUrl: 'views/Tools/ScreeningTool/FilterEdit.html', controller: 'EditFilterController'
            },
            new Routing.RouteSecurity().addResource({ verb: 'GET', resource: 'api/v1/filters/{filterId}', parameters: [] }),
            ['modules/CompanySearchModule/module.json', 'modules/LRTM/module.json', 'modules/Pager/module.json', 'modules/ScrollPager/module.json', 'modules/Company/module.json', 'modules/ScreeningTool/module.json', 'modules/GCCS.Security/module.json', 'modules/PI.Security/module.json', 'modules/ScreeningTool.Security/module.json'])

            .state('validationRules',
            {
                url: '/validationRules', templateUrl: 'views/ValidationRules/ValidationRules.html', controller: 'ValidationRulesController'
            },
            new Routing.RouteSecurity().addAdminResource(),
            ['modules/ValidationRules.Admin/module.json'])

            .otherwise('accounts', null);
    }]);


    // add sitemaps on module init
    mod.run(['NavigationService', (NavigationService: Navigation.INavigationService) => {

        // add sitemaps
        SiteMapUtility.addSiteMaps(NavigationService);
    }]);


    // bootstraping
    angular.element(document).ready(function () {
        angular.bootstrap.call(angular, document, ['main'], { strictDi: true });
    });
}